package com.admin.business.background.venusSysUserFranchise;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 加盟申请记录表
 * @create: 2023-11-04 17:15:37
 **/
@Service("venusSysUserFranchiseService")
@Slf4j
public class VenusSysUserFranchiseService{

    @Resource
    VenusSysUserFranchiseDao venusSysUserFranchiseDao;

    /**
     * 添加加盟申请记录表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - userId:用户ID
     *                   - invitationCode:邀请码
     *                   - payment:支付费用
     *                   - alreadyWithdrawal:已经提现
     *                   - totalAmount:提成总金额
     *                   - amountFreezing:冻结中金额
     *                   - agreement:是否同意协议：1、是，2、否
     *                   - withdrawable:可提现
     *                   - paymentStatus:申请状态：0，已支付，1，未支付，3、其他...
     *                   - examineStatus:审核状态：0、待审核，1、已审核
     *                   - beginTime:创建时间
     *                   - updateTime:更新时间
     *                   - updateNum:修改次数:0、未修改过,1、修改过
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return addVenusSysUserFranchise(CDO cdoRequest) {
        venusSysUserFranchiseDao.addVenusSysUserFranchise(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新加盟申请记录表数据
     *
     * @param cdoRequest - id:主键
     *                   - userId:用户ID
     *                   - invitationCode:邀请码
     *                   - payment:支付费用
     *                   - alreadyWithdrawal:已经提现
     *                   - totalAmount:提成总金额
     *                   - amountFreezing:冻结中金额
     *                   - agreement:是否同意协议：1、是，2、否
     *                   - withdrawable:可提现
     *                   - paymentStatus:申请状态：0，已支付，1，未支付，3、其他...
     *                   - examineStatus:审核状态：0、待审核，1、已审核
     *                   - beginTime:创建时间
     *                   - updateTime:更新时间
     *                   - updateNum:修改次数:0、未修改过,1、修改过
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return updateVenusSysUserFranchiseById(CDO cdoRequest) {
        venusSysUserFranchiseDao.updateVenusSysUserFranchiseById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除加盟申请记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return deleteVenusSysUserFranchiseById(CDO cdoRequest){
        int count = venusSysUserFranchiseDao.deleteVenusSysUserFranchiseById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除加盟申请记录表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return deleteVenusSysUserFranchise(CDO cdoRequest) {
        int count = venusSysUserFranchiseDao.deleteVenusSysUserFranchise(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取加盟申请记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return getVenusSysUserFranchiseById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysUserFranchiseDao.getVenusSysUserFranchiseById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取加盟申请记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return getVenusSysUserFranchiseListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysUserFranchiseDao.getVenusSysUserFranchiseListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysUserFranchiseDao.getVenusSysUserFranchiseCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取加盟申请记录表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 17:15:37
     */
    @OpenApi
    public Return getVenusSysUserFranchiseListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysUserFranchiseDao.getVenusSysUserFranchiseListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysUserFranchiseDao.getVenusSysUserFranchiseCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
